#include "commands.h"

static inline void send_command_to_cmus(char *command) {
    assert(command != NULL);

    /* toggle using cmus-remote */
    FILE *fp = popen(command, "r");
    if (fp == NULL) {
        fprintf(stderr, "cmus-remote error: command not found or failed to run\n");
        exit(EXIT_FAILURE);
    }

    pclose(fp);
}

void toggle_status(void *payload) {
    assert(payload == NULL);
    send_command_to_cmus("cmus-remote -u 2>&1");
}

void next(void *payload) {
    assert(payload == NULL);
    send_command_to_cmus("cmus-remote -n 2>&1");
}

void prev(void *payload) {
    assert(payload == NULL);
    send_command_to_cmus("cmus-remote -r 2>&1");
}

void toggle_aaa_mode(void *payload) {
    assert(payload == NULL);
    send_command_to_cmus("cmus-remote -C \"toggle aaa_mode\" 2>&1");
}